import {
  createRouter,
  createWebHashHistory,
  createWebHistory,
  RouteRecordRaw,
} from "vue-router";
// import {routerInterceptor} from "../util/routerBefore"
// import { useUserStore } from "@/store/user";
// const { user} = useUserStore();
//这里写所有非菜单栏控制的路由页面
//path:路径随意
//name:组件命名name
//component:组件
//meta {
//  cache:是否缓存
//
//}
//菜单栏路由配置页面,静态
const routes: RouteRecordRaw[] = [
  {
    path: "/",
    name: "Home",
    redirect: "/index",
    component: () => import("@/components/LayOut/index.vue"),
    children: [
      {
        path: "index",
        name: "Index",
        component: () => import("@/view/index.vue"),
        meta: {
          title: "数据分析",
          cache: false,
          active: true,
          icon: "House",
          hidden: false,
        },
        children: [],
      },
      {
        path: "/redirect",
        name: "Redirect",
        component: () => import("@/view/Redirect/index.vue"),
        meta: {
          title: "重定向",
          cache: false,
          active: false,
          icon: "House",
          hidden: true,
        },
      },
    ] as RouteRecordRaw[],
  },
  {
    path: "/login",
    name: "Login",
    meta: {
      title: "登录",
    },
    component: () => import("@/view/login.vue"),
  },
  {
    path: "/404",
    name: "Error",
    meta: {
      title: "404页面",
    },
    component: () => import("@/view/error/404.vue"),
  },
  {
    // path: "/:pathMatch(.*)*", // 这种写法会对路径进行解析，返回数组,主要是为了解决main.ts:31 [Vue Router warn]: No match found for location with path "/routerAdmin"这种警告。
    path: "/:pathMatch(.*)",
    component: Error,
  },
];
export const router = createRouter({
  //创建hash路由
  history: createWebHashHistory(),
  //创建history路由
  // history: createWebHistory(),
  routes: routes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});
export const goto = (name: string) => {
  router.push({ name: name });
};
